if [ -z "$1" ] || [ -z "$2" ] || [ $1 -le $2 ]; then
  echo "Wrong start/end date"
fi

machines=(
"feed-05.ap-northeast-1.aws"
"feed-01.ap-northeast-1.aws.huobi"
"feed-02.ap-northeast-2.aws"
"feed-02.eu-west-1.aws"
"feed-02.us-east-1.aws"
"feed-05.cn-hongkong.aliyun"
)

d=$1
ds=()
while [ $d -ge $2 ]
do
  ds+=($d)
  d=$(TZ="GMT" date -d "$d -1 day" "+%Y%m%d")
done

echo "${ds[@]}"

source /remote/iosg/home/bot-coin/miniconda3/etc/profile.d/conda.sh
conda activate coin2_env
set -x
EXIT_CODE=0
for d in "${ds[@]}"
do
  for m in "${machines[@]}"
  do
    rm -rf /remote/iosg/coin-2/feed_cache2/$m/$d/*
  done
  ./pyrunner coin/support/feed_tool/feed_cache/app/coin2_fast_feed_runner.py --trading_date=$d --arbitration=1 --worker=1 &
  wait $! || EXIT_CODE=$?
  echo "Finish $! $d! exit_code=${EXIT_CODE}"
done

conda deactivate